/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p/>
 * Compile: JDK 1.6+
 * <p/>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p/>
 * 公司名称：江苏欧索软件有限公司
 * <p/>
 * 公司地址：中国苏州科技城青山路1号
 * <p/>
 * 网址: http://www.oceansoft.com.cn
 * <p/>
 * 作者: 090922(陈伟)
 * <p/>
 * 文件名: com.oceansoft.mobile.econsole.modules.api.controller.ApiQueryController.java
 * <p/>
 * 类产生时间: 2014-7-22 0022 下午 16:41
 * <p/>
 * 负责人: 090922(陈伟)
 * <p/>
 * Email:javacspring@gmail.com
 * <p/>
 * 所在组 : 掌上公安应用平台
 * <p/>
 * 所在部门: 开发部--手持技术部
 * <p/>
 * <p/>
 */
package com.oceansoft.mobile.biz.api.controller;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.oceansoft.mobile.biz.api.webservice.IWebService;
import com.oceansoft.mobile.biz.api.webservice.SZRkkAuthNewPersonNameServiceServiceSoapBindingStub;
import com.oceansoft.mobile.biz.api.webservice.TrafficVehicleService;
import com.oceansoft.mobile.weixin.util.IdcardUtil;
import com.oceansoft.mobile.weixin.util.WeixinUtil;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oceansoft.mobile.common.Constant;
import com.oceansoft.mobile.common.dao.ICommonDao;
import com.oceansoft.mobile.common.util.CacheBaseService;
import com.oceansoft.mobile.common.util.HttpClientUtil;
import com.oceansoft.mobile.common.util.Result;


/**
 * 查询服务
 *
 * @author: zhuwj
 * @time: 20160402 下午 20:41
 */
@Controller
@RequestMapping("api/query")
public class ApiQueryController {
    private static Logger logger = LoggerFactory.getLogger(ApiQueryController.class);
    
    @Resource
    private ICommonDao commonDao;
    private TrafficVehicleService tvs;
    
    @RequestMapping(value = "{pageName}", method = RequestMethod.GET)
    public void gotoPages(@PathVariable("pageName") String pageName, HttpServletRequest request, HttpServletResponse response) {
        try {
            String page = "/static/plugins/" + pageName + ".html";
            request.getRequestDispatcher(page).forward(request, response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
//	        return "plugins/" + pageName;
    }

    /**
     * 重名查询
     *
     * @param name 待查询姓名
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "name")
    public Result duplicationNameQuery(@RequestParam("name") String name,HttpServletRequest request) throws IOException {
    	//WeixinUtil.gesearchCountInfo("15","其他");//统计方法调用（暂时用不到）
        if (StringUtils.hasLength(name)) {
            String key = "duplicationNameQuery=" + name;
            
            try{
            String openId = (String)request.getSession().getAttribute("openId");
            if(com.oceansoft.mobile.common.util.StringUtils.isNotEmpty(openId)){
                commonDao.update("insert into t_cmcx_tj value (NOW(),?,?)", name,openId);
            }
            }catch(Exception e)
            {
            	e.printStackTrace();
            }
            
            Result r = null;
            if (CacheBaseService.getInstance().exists(key)) {
                r = CacheBaseService.getInstance().getObject(key, Result.class);
            } else {
                try {

                    long begin = System.currentTimeMillis();
                    String url = "http://www.szrkk.suzhou.gov.cn:8080/net-webservice/services/SZRkkAuthNewPersonNameService";
                    String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
                    xml += "<Request>";
                    xml += "<Head> ";
                    xml += "<DeptID>GONGANJU</DeptID>";
                    xml += "<SysInfo>苏州公安微信</SysInfo>";
                    xml += "<APPID>WX</APPID>";
                    xml += "</Head>";
                    xml += "<Body>";
                    xml += "<name>" + name + "</name>";
                    xml += "</Body>";
                    xml += "</Request>";

                    IWebService webservice = new SZRkkAuthNewPersonNameServiceServiceSoapBindingStub(
                            new java.net.URL(url), null);
                    String str = webservice.execute(xml);
                    long end = System.currentTimeMillis();
                    //System.out.println("结果：" + str);
                    System.out.println("查询时间：" + (end - begin));

                    Document doc = DocumentHelper.parseText(str);
                    Element root = doc.getRootElement();
                    Element head = root.element("Head");
                    String status = head.element("Status").getData().toString();
                    Element body = root.element("Body");
                    List nodes = body.elements("RESULT");
                    Map<String, Map<String, Integer>> map = new HashMap<String, Map<String, Integer>>();
                    Map<String, Integer> ages = new HashMap<String, Integer>();
                    Map<String, Integer> genders = new HashMap<String, Integer>();
                    Map<String, Integer> constellations = new HashMap<String, Integer>();
                    //初始
                    ages.put("age20", 0);
                    ages.put("age2030", 0);
                    ages.put("age3040", 0);
                    ages.put("age4050", 0);
                    ages.put("age5060", 0);
                    ages.put("age60", 0);
                    genders.put("male", 0);
                    genders.put("female", 0);
                    constellations.put("sp", 0);
                    constellations.put("sy", 0);
                    constellations.put("by", 0);
                    constellations.put("jn", 0);
                    constellations.put("shuangzi", 0);
                    constellations.put("jx", 0);
                    constellations.put("shizi", 0);
                    constellations.put("cn", 0);
                    constellations.put("tx", 0);
                    constellations.put("ss", 0);
                    constellations.put("mj", 0);
                    constellations.put("tp", 0);

                    for (Iterator it = nodes.iterator(); it.hasNext(); ) {
                        Element elm = (Element) it.next();
                        int age = IdcardUtil.getAgeByIdCard(elm.getData()
                                .toString());
                        String gender = IdcardUtil.getGenderByIdCard(elm
                                .getData().toString());
                        String constellation = IdcardUtil.getConstellationById(
                                elm.getData().toString(), false);
                        //00000000000000**0* 算女 60岁以上 摩羯
                        // 年龄
                        if (age < 20) {
                            ages.put("age20", ages.get("age20") + 1);
                        } else if (age >= 20 && age < 30) {
                            ages.put("age2030", ages.get("age2030") + 1);
                        } else if (age >= 30 && age < 40) {
                            ages.put("age3040", ages.get("age3040") + 1);
                        } else if (age >= 40 && age < 50) {
                            ages.put("age4050", ages.get("age4050") + 1);
                        } else if (age >= 50 && age < 60) {
                            ages.put("age5060", ages.get("age5060") + 1);
                        } else {
                            ages.put("age60", ages.get("age60") + 1);
                        }
                        // 性别
                        if ("男".equals(gender)) {
                            genders.put("male", genders.get("male") + 1);
                        } else if ("女".equals(gender)) {
                            genders.put("female", genders.get("female") + 1);
                        }
                        // 星座
                        if ("水瓶座".equals(constellation)) {
                            constellations.put("sp",
                                    constellations.get("sp") + 1);
                        } else if ("双鱼座".equals(constellation)) {
                            constellations.put("sy",
                                    constellations.get("sy") + 1);
                        } else if ("白羊座".equals(constellation)) {
                            constellations.put("by",
                                    constellations.get("by") + 1);
                        } else if ("金牛座".equals(constellation)) {
                            constellations.put("jn",
                                    constellations.get("jn") + 1);
                        } else if ("双子座".equals(constellation)) {
                            constellations.put("shuangzi",
                                    constellations.get("shuangzi") + 1);
                        } else if ("巨蟹座".equals(constellation)) {
                            constellations.put("jx",
                                    constellations.get("jx") + 1);
                        } else if ("狮子座".equals(constellation)) {
                            constellations.put("shizi",
                                    constellations.get("shizi") + 1);
                        } else if ("处女座".equals(constellation)) {
                            constellations.put("cn",
                                    constellations.get("cn") + 1);
                        } else if ("天秤座".equals(constellation)) {
                            constellations.put("tp",
                                    constellations.get("tp") + 1);
                        } else if ("天蝎座".equals(constellation)) {
                            constellations.put("tx",
                                    constellations.get("tx") + 1);
                        } else if ("射手座".equals(constellation)) {
                            constellations.put("ss",
                                    constellations.get("ss") + 1);
                        } else {
                            constellations.put("mj",
                                    constellations.get("mj") + 1);
                        }

                    }
                    map.put("ages", ages);
                    map.put("genders", genders);
                    map.put("constellations", constellations);
//					System.out.println(JSON.toJSONString(map));
                    r = new Result();
                    r.setData(map);
                    if("0001".equals(status)) {
                        CacheBaseService.getInstance().cache(key, r, 1f);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return r;

        } else {
            return new Result("请输入查询用户名!");
        }

    }

    /**
     * 身份证办理进度信息查询
     *
     * @param idNum     身份证号
     * @param pendingId 受理编号
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "progress/idcard", method = POST)
    public Result idCardDealProgressQuery(@RequestParam("idCard") String idNum, @RequestParam("pendingId") String pendingId) throws IOException {
    	WeixinUtil.gesearchCountInfo("2","身份证进度查询");//统计方法调用
        String url = Constant.host5 + "api/searchinfo/GetSFZJDInfo?sfzno=" + idNum + "&sjno=" + pendingId;
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 案件信息查询
     *
     * @param idCard    身份证号码
     * @param pendingId 办件编号
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "caseinfo", method = POST)
    public Result loadCaseDetail(@RequestParam("idCard") String idCard, @RequestParam("pendingId") String pendingId) throws IOException {
    	WeixinUtil.gesearchCountInfo("10","案件查询");//统计方法调用
        String url = Constant.host5 + "api/SearchInfo/GetAJSearchInfo?sfzno=" + idCard + "&jjno=" + pendingId;
        return getDataFromCacheOrRemote(url);
    }


    /**
     * 办件进度信息查询
     *
     * @param caseId 办件编号
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "progress/case/{case_id}", method = GET)
    public Result loadDoScheduleDetail(@PathVariable("case_id") String caseId) throws IOException {
    	//WeixinUtil.gesearchCountInfo("12","办件查询");//统计方法调用
        String url = Constant.host5 + "api/Progress/Progress?prjNo=" + caseId;
        Result r = null;
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 居住证办理进度信息查询
     *
     * @param idNum 身份证号
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "progress/residence/{id_num}", method = GET)
    public Result loadPermitDetailInfo(@PathVariable("id_num") String idNum) throws IOException {
        //return mattersService.loadPermitScheduleDetail(idNum);
    	WeixinUtil.gesearchCountInfo("1","居住证办理进度查询");//统计方法调用
        String url = Constant.host5 + "api/searchinfo/GetJZZJDInfo?sfzno=" + idNum;
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 居住证办理地点信息查询
     *
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "location/permit/{orgguid}", method = GET)
    public Result loadPermitOfficeDetail(@PathVariable("orgguid") String orgguid) throws IOException {
    	WeixinUtil.gesearchCountInfo("3","居住证办理点查询");//统计方法调用
        String url = Constant.host5 + "api/searchinfo/GetJZZJDInfo?orgguid=" + orgguid;
        return getDataFromCacheOrRemote(url);
    }

    /***
     * 户口办理审批结果查询
     * @param request
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(value = "progress/residence", method = POST)
    public Result queryResidence(HttpServletRequest request) throws IOException {
    	//WeixinUtil.gesearchCountInfo("15","其他");//统计方法调用（暂时用不到）
        String name = request.getParameter("username");
        String idcard = request.getParameter("idcard");
        String url = Constant.host5 + "api/searchinfo/GetHKBLSPJGInfo?name=" + name + "&sfno=" + idcard;
        return getDataFromCacheOrRemote(url);
    }
    
    /**
     * 外来人口积分查询
     * @param request
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(value = "queryPointsScore", method = POST)
    public Result queryPointsScore(HttpServletRequest request) throws IOException {
    	//WeixinUtil.gesearchCountInfo("15","其他");//统计方法调用（暂时用不到）
        String sbk = request.getParameter("sbk");
        String idcard = request.getParameter("idcard");
        String url = "http://221.224.13.2:2016/apms/statistics/queryPointsScore?idcard="+idcard+"&sbk="+sbk;
        Result r = null; 
        if (CacheBaseService.getInstance().exists(url)) {
            r = CacheBaseService.getInstance().getObject(url, Result.class);
        } else {
        	//{"name":null,"state":"3","idcard":null,"scores":0,"rank":0,"baseScore":0,"additionalScore":0,"subScore":0}
            String a  = HttpClientUtil.doGet(url);
            r = new Result();
            r.setMsg("查询成功!");
            r.setSucc(true);
            r.setData(JSONObject.parse(a));
            if (r != null && r.isSucc()) {
                CacheBaseService.getInstance().cache(url, r, 1f);
            }
        }
        return r;
    }

    /**
     * 加载全部苏州市局及分局信息
     *
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "police-bureaus", method = GET)
    public Result loadAllBuresau() throws IOException {
        String url = Constant.host + "/api/query/police-bureaus";
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 加载全部警钟
     *
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "police-catalogs", method = GET)
    public Result loadAllCatalogs() throws IOException {
        String url = Constant.host + "/api/query/police-catalogs";
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 获取事项数据
     *
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "case", method = GET)
    public Result getMatters(HttpServletRequest request) throws IOException {
        String type = request.getParameter("type");
        String bureausId = request.getParameter("bureausId");
        String catalog = request.getParameter("catalog");
        String policeId = request.getParameter("policeId");
        String subject = request.getParameter("subject");
        String pageIndex = request.getParameter("pageIndex");
        String keyword = request.getParameter("keyword");
        String pageSize = request.getParameter("pageSize");
        String url = Constant.host + "/api/matters/page/case.json?type=" + type + "&bureausId=" + bureausId + "&catalog=" + catalog + "&policeId=" + policeId + "&subject=" + subject + "&pageIndex=" + pageIndex + "&keyword=" + keyword + "&pageSize=" + pageSize;
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 加载苏州市局及分局科室信息
     *
     * @param bureauId 市局或分局ID
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "bureau-depts/{bureau_id}", method = GET)
    public Result loadAllDepartments(@PathVariable("bureau_id") String bureauId) throws IOException {
        String url = Constant.host + "/api/query/bureau-depts/" + bureauId;
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 分局下所有的派出所
     *
     * @param bureauId 分局id
     * @return Result
     */
    @ResponseBody
    @RequestMapping(value = "police-stations/{bureau_id}")
    public Result loadPoliceStation(@PathVariable("bureau_id") String bureauId) throws IOException {
        String url = Constant.host + "/api/query/police-stations/" + bureauId;
        return getDataFromCacheOrRemote(url);
    }

    /**
     * 获取派出所下所有警务室
     *
     * @param officeId 派出所id
     * @return ModelAndView
     */
    @ResponseBody
    @RequestMapping(value = "police-offices/{office_id}")
    public Result loadPoliceOffices(@PathVariable("office_id") String officeId) throws IOException {
        String url = Constant.host + "/api/query/police-offices/" + officeId;
        return getDataFromCacheOrRemote(url);
    }

    /***
     * GET请求远程数据，缓存在redis一天
     * @param url
     * @return
     */
    private Result getDataFromCacheOrRemote(String url) throws IOException {
        Result r = null;
        if (CacheBaseService.getInstance().exists(url)) {
            r = CacheBaseService.getInstance().getObject(url, Result.class);
        } else {
            r = HttpClientUtil.doGAGet(url);
            if (r != null && r.isSucc()) {
                CacheBaseService.getInstance().cache(url, r, 1f);
            }
        }
        return r;
    }

    //	public static void main(String[] args) {
//		String url = "http://172.16.1.250/e/extend/index.php?s=api/ask";
//        Result r = null;
//        	Map<String, String> param=new HashMap<String, String>();
//        	param.put("title","test_title");
//        	param.put("content","test_content");
//        	param.put("people_name","test_people_name");//创建人姓名
//        	param.put("people_contact","test_people_contact");//创建人联系方式
//        	param.put("channel_user","1");//创建人guid
//        	param.put("type_id","1");
//        	String response=HttpClientUtil.doPost(url, param, "utf-8");
//        	System.out.println(StringEscapeUtils.unescapeJava(response));
//	}
    
    
    @ResponseBody
	@RequestMapping(value = "vehicle/{hphm}/{vin}")
	public JSONObject queryVehicle(HttpServletRequest request,
			@PathVariable("hphm") String hphm,
			@PathVariable("vin") String vin) {
		if(StringUtils.hasText(hphm)&&hphm.startsWith("苏"))
		{
			hphm = hphm.substring(1,hphm.length()-1);
		}
		tvs = TrafficVehicleService.getInstance();
		String info =  "";
		try{
			info = tvs.getVehicleiInfo(hphm, vin);
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		//{"msg":"获取机动车基本信息成功","result":true,"vehicle":{"BXZZRQ":"2017-04-28T00:00:00","CCDJRQ":"2016-05-03T12:59:47","CCRQ":"2016-07-06T17:37:35.5588872+08:00","CLSBDH":"YV1MV2923G2334146","CWKC":0,"CWKG":0,"CWKK":0,"DYBJ_NAME":"已抵押","GBTHPS":0,"GL":0.0,"HDZK":0,"HDZZL":0,"HPHM":"E9GT78","HPZK":0,"HPZL_NAME":"小型汽车","HXNBCD":0,"HXNBGD":0,"HXNBKD":0,"PL":0,"QPZK":0,"QZBFQZ":"2016-07-06T17:37:35.5588872+08:00","SYR":"朱伟家","YXQZ":"2018-05-31T00:00:00","ZBZL":0,"ZQYZL":0,"ZS":0,"ZT":"A","ZT_NAME":"正常","ZZL":0}} 
		JSONObject json =  JSONObject.parseObject(info);
		String msg = (String)json.get("msg");
		System.out.println("msg=="+msg);
		return json;
	}
	
	@ResponseBody
	@RequestMapping(value = "surveil/{hphm}/{vin}")
	public JSONObject querySurveil(HttpServletRequest request,
			@PathVariable("hphm") String hphm,
			@PathVariable("vin") String vin) {
		if(StringUtils.hasText(hphm)&&hphm.startsWith("苏"))
		{
			hphm = hphm.substring(1,hphm.length());
			hphm = hphm.toUpperCase();
		}
		vin = vin.toUpperCase();
		String key = "traffic:"+hphm+"_"+vin;
		JSONObject json = new JSONObject();
		//数据缓存
		if (CacheBaseService.getInstance().exists(key)) { 
			json = CacheBaseService.getInstance().getObject(key,
					JSONObject.class);
			//System.out.println("缓存");
		} 
		else
		{
			//{"result":true,"msg":"获取未处理的机动车交通违法信息成功","vioSurveil":[{"XH":"3213237901617354","HPZL":null,"HPHM":null,"CLSBDH":null,"CJJGMC":"泗阳大队","WFSJ":"2016-04-22T10:45:00","WFDZ":"青泗线（245省道）131公里900米","WFXW":"驾驶中型以上载客载货汽车、危险物品运输车辆以外的其他机动车行驶超过规定时速10%未达20%的","CLBJ":null,"JKBJ":null,"WFJFS":0,"FKJE":"50","ZT":"未处理未交款","WFJFS1":"3"},{"XH":"3205080011612849","HPZL":null,"HPHM":null,"CLSBDH":null,"CJJGMC":"苏州市城市管理执法局","WFSJ":"2016-05-12T09:39:00","WFDZ":"虎阜路虎阜路999号虎丘婚纱城门口人行道板上","WFXW":"机动车违反规定停放、临时停车妨碍其他车辆、行人通行的，驾驶人不在现场的","CLBJ":null,"JKBJ":null,"WFJFS":0,"FKJE":"50","ZT":"未处理未交款","WFJFS1":"0"}]}
			tvs = TrafficVehicleService.getInstance();
			try{
				String info = tvs.getVioSurveil("02", hphm, vin);
				json =  JSONObject.parseObject(info);
				//获取图片
				JSONArray wzs = (JSONArray) json.get("vioSurveil");
				for (Object object : wzs) {
					String xh = (String)((JSONObject)object).get("XH");
					//System.out.println(xh);
					String photo = tvs.getPhotoByXH(xh);
					JSONObject ps =   JSONObject.parseObject(photo);
					if((Boolean)ps.get("result"))
					{
						//System.out.println(ps.get("msg"));
						((JSONObject)object).put("photo", ps.get("photo"));
					}
				}
				CacheBaseService.getInstance().cache(key,json,1f);
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}
//		String msg = (String)json.get("msg");
		//System.out.println("msg=="+msg);
		return json;
	}
	
	
	@ResponseBody
	@RequestMapping(value = "violation/{jszh}/{dabh}")
	public JSONObject getViolation(HttpServletRequest request,
			@PathVariable("jszh") String jszh,
			@PathVariable("dabh") String dabh) {
		if(StringUtils.hasText(jszh))
		{
			jszh = jszh.toUpperCase();
		}
		String key = "traffic:"+jszh+"_"+dabh;
		JSONObject json = new JSONObject();
		//数据缓存
		if (CacheBaseService.getInstance().exists(key)) { 
			json = CacheBaseService.getInstance().getObject(key,
					JSONObject.class);
			//System.out.println("缓存");
		} 
		else
		{
			//{"msg":"获取驾驶证交通违法信息成功","result":true,"violation":[{"CFZL":"罚款","CLJGMC":"常熟市公安局交通巡逻警察大队车管所","CLSJ":"2012-07-09T13:17:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟市公安局交通巡逻警察大队车管所","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320581170045263","JKRQ":"2012-07-09T00:00:00","WFDZ":"204国道老线895公里","WFJFS":3,"WFNR":"机动车未按照规定期限进行安全技术检验","WFSJ":"2012-07-09T13:17:00","WFXW":"1340","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓大队城厢中队","CLSJ":"2011-11-04T12:20:00","FKJE":50,"FLAG":0,"FXJGMC":"太仓大队城厢中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585199554534","JKRQ":"2012-05-14T00:00:00","WFDZ":"浏昆线（339省道）","WFJFS":0,"WFNR":"机动车驾驶人有其它违反道路通行规定的行为的","WFSJ":"2011-11-04T12:20:00","WFXW":"7005","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓大队南郊中队","CLSJ":"2011-11-03T07:58:00","FKJE":100,"FLAG":0,"FXJGMC":"太仓大队南郊中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585199558186","JKRQ":"2012-05-14T00:00:00","WFDZ":"烟沪线（204国道）","WFJFS":0,"WFNR":"公路客运车辆以外的载客汽车违反规定载货的","WFSJ":"2011-11-03T07:58:00","WFXW":"1092","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"相城大队渭塘中队","CLSJ":"2011-09-30T16:03:00","FKJE":50,"FLAG":0,"FXJGMC":"相城大队渭塘中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320507199252608","JKRQ":"2012-05-14T00:00:00","WFDZ":"S227渭塘段","WFJFS":1,"WFNR":"上道路行驶的机动车未放置保险标志的","WFSJ":"2011-09-30T16:03:00","WFXW":"1108","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓市交巡警大队浏河中队","CLSJ":"2010-12-21T00:00:00","FKJE":100,"FLAG":0,"FXJGMC":"太仓市交巡警大队浏河中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585167427187","JKRQ":"2010-12-21T00:00:00","WFDZ":"338省道","WFJFS":0,"WFNR":"公路客运车辆以外的载客汽车违反规定载货的","WFSJ":"2010-12-21T13:33:04","WFXW":"1092","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓市交巡警大队秩序科","CLSJ":"2010-11-17T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"太仓市交巡警大队秩序科","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585068040737","JKRQ":"2010-11-17T00:00:00","WFDZ":"900600000000","WFJFS":0,"WFNR":"机动车违反规定停放、临时停车，妨碍其它车辆、行人通行，驾驶人不在现场的","WFSJ":"2010-10-25T08:27:14","WFXW":"10391","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队","CLSJ":"2010-06-29T00:00:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏ETJ356","HPZL":"小型汽车","JDSBH":"320581151627546","JKRQ":"2010-06-29T00:00:00","WFDZ":"162220000000","WFJFS":0,"WFNR":"机动车行驶超过规定时速20%以上未达50%的","WFSJ":"2010-04-25T12:33:21","WFXW":"13033","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队","CLSJ":"2010-06-29T00:00:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏ETJ356","HPZL":"小型汽车","JDSBH":"320581151627545","JKRQ":"2010-06-29T00:00:00","WFDZ":"150860000000","WFJFS":0,"WFNR":"机动车行驶超过规定时速20%以上未达50%的","WFSJ":"2010-03-25T15:23:23","WFXW":"13033","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓市交巡警大队秩序科","CLSJ":"2010-03-10T00:00:00","FKJE":100,"FLAG":0,"FXJGMC":"太仓市交巡警大队秩序科","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585068040024","JKRQ":"2010-03-10T00:00:00","WFDZ":"900570000000","WFJFS":0,"WFNR":"机动车通过有灯控路口时，不按所需行进方向驶入导向车道的","WFSJ":"2009-12-11T15:01:30","WFXW":"1208","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队","CLSJ":"2010-06-29T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏ETJ356","HPZL":"小型汽车","JDSBH":"320581151627544","JKRQ":"2010-06-29T00:00:00","WFDZ":"153170000000","WFJFS":0,"WFNR":"机动车行驶超过规定时速10%以上未达20%的","WFSJ":"2009-10-08T11:35:23","WFXW":"13032","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"警告","CLJGMC":"常熟市交巡警大队辛庄中队","CLSJ":"2009-09-28T08:46:16","FKJE":0,"FLAG":0,"FXJGMC":"常熟市交巡警大队辛庄中队","HPHM":"苏EXR753","HPZL":"普通摩托车","JDSBH":"320581199415458","WFDZ":"205省道","WFJFS":0,"WFNR":"驾驶摩托车时驾驶人未按规定戴安全头盔的","WFSJ":"2009-09-28T08:45:00","WFXW":"1207","XXLY":"现场处罚","ZT":"无需交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队辛庄中队","CLSJ":"2009-03-19T08:54:23","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队辛庄中队","HPHM":"苏EXR753","HPZL":"普通摩托车","JDSBH":"320581051710121","JKRQ":"2009-03-19T08:54:23","WFDZ":"205省道","WFJFS":0,"WFNR":"上道路行驶的机动车未按规定放置检验合格标志","WFSJ":"2009-03-19T07:10:00","WFXW":"1071","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队辛庄中队","CLSJ":"2009-07-01T14:49:41","FKJE":200,"FLAG":0,"FXJGMC":"常熟市交巡警大队辛庄中队","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581151002632","JKRQ":"2009-07-01T14:49:41","WFDZ":"205省道","WFJFS":0,"WFNR":"驾驶未经检验合格的机动车","WFSJ":"2008-03-20T07:10:00","WFXW":"7002","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队海虞中队","CLSJ":"2007-03-13T10:16:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队海虞中队","HPHM":"苏EE8709","HPZL":"小型汽车","JDSBH":"320581031625521","JKRQ":"2007-03-13T10:16:00","WFDZ":"谢桥镇","WFJFS":0,"WFSJ":"2007-03-13T10:13:00","WFXW":"9088","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队海虞中队","CLSJ":"2007-03-13T10:16:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队海虞中队","HPHM":"苏EE8709","HPZL":"小型汽车","JDSBH":"320581031625520","JKRQ":"2007-03-13T10:16:00","WFDZ":"谢桥镇","WFJFS":0,"WFNR":"变更车道时影响正常行驶的机动车的","WFSJ":"2007-03-13T10:12:00","WFXW":"1043","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟大队秩序科","CLSJ":"2006-08-29T00:00:00","FKJE":100,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏EEF640","HPZL":"小型汽车","JDSBH":"320581051204028","JKRQ":"2006-08-29T00:00:00","WFDZ":"锁澜路","WFJFS":0,"WFSJ":"2006-08-23T15:19:00","WFXW":"9018","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队城区中队","CLSJ":"2006-07-12T10:17:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队城区中队","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581031422345","JKRQ":"2006-07-12T10:17:00","WFDZ":"总马桥街","WFJFS":2,"WFNR":"驾驶摩托车时驾驶人未按规定戴安全头盔的","WFSJ":"2006-07-12T10:13:00","WFXW":"1207","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市城市巡逻警察大队","CLSJ":"2005-07-23T00:00:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟市城市巡逻警察大队","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581011675830","JKRQ":"2005-07-23T00:00:00","WFDZ":"红旗南、北路","WFJFS":0,"WFNR":"驾驶未经检验合格的机动车","WFSJ":"2005-07-23T19:35:33","WFXW":"7002","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟大队秩序科","CLSJ":"2005-02-25T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏EB9044","HPZL":"小型汽车","JDSBH":"320581011703369","JKRQ":"2005-02-25T00:00:00","WFDZ":"205省道","WFJFS":3,"WFNR":"机动车行驶超过规定时速10%以上未达20%的","WFSJ":"2005-02-25T17:42:00","WFXW":"13032","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟大队秩序科","CLSJ":"2005-02-08T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏EB9044","HPZL":"小型汽车","JDSBH":"320581011703368","JKRQ":"2005-02-08T00:00:00","WFDZ":"205省道","WFJFS":3,"WFNR":"机动车行驶超过规定时速10%以上未达20%的","WFSJ":"2005-02-08T16:30:00","WFXW":"13032","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队警务通","CLSJ":"2004-08-25T09:35:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队警务通","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581031035778","JKRQ":"2004-08-25T09:35:00","WFDZ":"环城路","WFJFS":2,"WFNR":"驾驶摩托车时驾驶人未按规定戴安全头盔的","WFSJ":"2004-08-25T09:35:00","WFXW":"1207","XXLY":"现场处罚","ZT":"已交款"}]}
			tvs = TrafficVehicleService.getInstance();
			try{
				String info = tvs.getViolation(jszh, dabh);
				json =  JSONObject.parseObject(info);
				CacheBaseService.getInstance().cache(key,json,1f);
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}
//		String msg = (String)json.get("msg");
		//System.out.println("msg=="+msg);
		return json;
	}

    public static void main(String[] args) {
        String url = "http://172.16.1.250/e/extend/index.php?s=api/getask";
        Result r = null;
        Map<String, String> param = new HashMap<String, String>();
        //{page=1, keyword=, channel_user=808c55fb-2d75-4f12-b72a-6269745c62d0, channel_id=4, type_id=1, pagerows=5}
        //{page=1, keyword=7, channel_user=0a1d1c76-eb80-4bda-858a-9b88f88a1eb3, channel_id=4, type_id=1,2, pagerows=5}
        param.put("channel_user", "808c55fb-2d75-4f12-b72a-6269745c62d0");
        //param.put("channel_user","0a1d1c76-eb80-4bda-858a-9b88f88a1eb3");
        param.put("keyword", "");
        param.put("type_id", "1,2");
        param.put("page", "1");
        param.put("pagerows", "5");
        param.put("channel_id", "4");//1 网厅     	2app  	3 微信
        String response = HttpClientUtil.doPost(url, param, "utf-8");
        System.out.println(StringEscapeUtils.unescapeJava(response));
    }
}
